package mailsystem.states;

import mailsystem.Connection;
import mailsystem.Mailbox;
import mailsystem.TelephoneResources;

public class AddContactStatus implements State {

	@Override
	public void runAction(Connection c, String key)
	{
		if (key.equals("#")) {
			Mailbox box = c.getSystem().findMailbox(c.getAccumulatedKeys());
			if (box != null) {
				c.getCurrentMailbox().addContact(c.getAccumulatedKeys(), box);				
				c.speakAllPhones(box.getName() + TelephoneResources.CONTACT_ADDED, TelephoneResources.CONTACT_ADDED_AUDIO);
			} else
				c.speakAllPhones(TelephoneResources.INCORRECTMAILBOX, TelephoneResources.INCORECTMAILBOX_AUDIO);
			c.setState(Connection.MAILBOXMENU);			
			c.showDisplayAllPhones(TelephoneResources.MAILBOX_MENU_TEXT);
			c.setAccumulatedKeys("");
		} else
			c.setAccumulatedKeys(c.getAccumulatedKeys() + key);
	}

}
